'use strict'
define(['services/routeResolver'],function(){
    var app = angular.module('DishApp',['ngRoute','ngSanitize','routeResolverServices']);

    app.config(['$routeProvider','routeResolverProvider','$controllerProvider','$compileProvider','$filterProvider','$provide','$httpProvider',
        function($routeProvider, routeResolverProvider, $controllerProvider, $compileProvider, $filterProvider, $provide, $httpProvider){
            // change default views and controllers directory using the following:
            // routeResolverProvider.routeConfig.setBaseDirectories('app/views','/app/controllers');

            app.register = {
                controller: $controllerProvider.register,
                service: $provide.service
            };

            // defne routes - controllers will be loaded dynamically
            var route = routeResolverProvider.route;

            $routeProvider
                .when('/',
                    route.resolve(
                        'list.html','list-controller.js','IndexCtrl'))
                .otherwise({
                    redirectTo:'/'
                });
        }
    ])

    // filters
    app.filter('newlines', function(){
        return function(text){
            return text.replace(/\n/g, '<br/>');
        }
    });

    app.filter('noHTML', function(){
        return function(text){
            return text
                .replace(/&/g, '&amp;')
                .replace(/>/g, '&gt;')
                .replace(/</g, '&lt;');
        }
    });

    app.filter('styleMin', function(){
        return function(text){
            return text.substring(0,3).toUpperCase();
        }
    })

    app.filter('range', function($log){
        return function(input){
            var lowBound, highBound;
            switch(input.length){
                case 1:
                    lowBound = 0;
                    highBound = parseInt(input[0]) - 1;
                    break;
                case 2:
                    lowBound = parseInt(input[0]);
                    highBound = parseInt(input[1]);
                    break;
                default:
                    return input;
            }
            var result = [];
            for(var i=lowBound;i<=highBound;i++){
                result.push(i);
            }
            return result;
        }
    });

    return app;
})





